
using GameFramework;
using Newtonsoft.Json;
using System;

namespace Local
{
    public class NewtonsoftJsonHelper : Utility.Json.IJsonHelper
    {
        JsonSerializerSettings jsonSetting;
        public NewtonsoftJsonHelper()
        {
            jsonSetting = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto,
                Formatting = Formatting.Indented,
                //ContractResolver = new SerializeFieldResolver()
            };
        }
        public string ToJson(object obj)
        {
            return JsonConvert.SerializeObject(obj, jsonSetting);
        }

        public T ToObject<T>(string json)
        {
            return JsonConvert.DeserializeObject<T>(json, jsonSetting);
        }

        public object ToObject(Type objectType, string json)
        {
            return JsonConvert.DeserializeObject(json,objectType, jsonSetting);
        }
    }

}
